package main.java.dao.impl;

import main.java.dao.ResultDao;
import main.java.domain.Result;
import main.java.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class ResultDaoImpl implements ResultDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    @Override
    public void add(int stuid, int taskid, String path) {
        String sql = "insert into result values("+stuid+", "+taskid+", null, null, '"+path+"')";

        template.update(sql);
    }

    @Override
    public void update(int stuid, int taskid, int res, String eval) {
        String sql = "update result set res = "+res+", eval = '"+eval+"' WHERE stuid = "+stuid+" and taskid = "+taskid;

        template.update(sql);
    }

    @Override
    public Result find(int stuid, int taskid) {
        String sql = "select * from result where stuid = ? and taskid = ?";
        return template.queryForObject(sql, new BeanPropertyRowMapper<Result>(Result.class), stuid, taskid);
    }
}
